//
//  SearchKeyWordManager.m
//  AppointmentForCar
//
//  Created by ZengPengYuan on 2016/11/14.
//  Copyright © 2016年 Herron. All rights reserved.
//

#import "SearchKeyWordManager.h"


@interface SearchKeyWordManager () <BMKPoiSearchDelegate>
@property (nonatomic , strong) BMKPoiSearch * poisearch;
@property (nonatomic , copy) searchResultBlock result;
@end
@implementation SearchKeyWordManager


- (void)searchCity:(NSString *)cityName keyWord:(NSString *)keyWord complete:(searchResultBlock)complete {
    BMKCitySearchOption *citySearchOption = [[BMKCitySearchOption alloc]init];
    citySearchOption.pageIndex = 0;
    citySearchOption.pageCapacity = 10;
    citySearchOption.city= cityName;
    citySearchOption.keyword = keyWord;
    BOOL flag = [_poisearch poiSearchInCity:citySearchOption];
    if(flag) {
        NSLog(@"城市内检索发送成功");
        self.result = complete;
    } else {
        complete(nil, @"搜索失败");
        NSLog(@"城市内检索发送失败");
    }
}

#pragma mark - BMKPoiSearchDelegate
- (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResult errorCode:(BMKSearchErrorCode)errorCode {
    if(errorCode == BMK_SEARCH_NO_ERROR)
    {
        _result(poiResult.poiInfoList, nil);
    }
}

- (instancetype)init {
    self = [super init];
    if(self) {
        self.poisearch.delegate = self;
    }
    return self;
}

- (BMKPoiSearch *)poisearch {
    if(!_poisearch) {
        _poisearch = [[BMKPoiSearch alloc] init];
    }
    return _poisearch;
}

- (void)dealloc {
    if(_poisearch) {
        _poisearch.delegate = nil;
        _poisearch = nil;
    }
}

@end
